<?php

class connexionValidationUser extends Controller {


	function index()
	{
		$this->load->database();
		$this->load->library('form_validation');
		$this->load->helper('form');
		$this->load->helper('url');
		$this->load->helper('cookie');
		
		
		
		$data;
		
		$this->form_validation->set_rules('login',  'login', 'required');	
		$this->form_validation->set_rules('password',  'password', 'required');
		
		$this->form_validation->set_message('required', 'Vous n\'avez pas renseigner le champs %s ');
	
		
		if ($this->form_validation->run() ){ 
		
			$query = $this->db->query("SELECT password FROM utilisateur where pseudo='".$this->input->post('login')."'");
			$row = $query->row_array();
		
			if ( $query->num_rows() ==0 || $row['password']!= $this->input->post('password')){
		
				$data["message"]="Echec de connexion.";
				$this->load->view('connexionUser',$data);
			}
		
			else{	
				
				/*$cookie = array(
                   'name'   => 'login',
				   'value'  => $this->input->post('login'), 
				);*/
			

				//set_cookie($cookie); 
				
				setcookie('login',$this->input->post('login'));
				
				$data["login"]=$this->input->post('login');
				$this->load->view('connexionValidationUser',$data);
		
				}
		}
		
		else $this->load->view('connexionUser');
		
	}
	
	
}
?>